/*
 * AppointmentController.java
 */
package edu.gatech.oad.schedule;
import edu.gatech.oad.user.Doctor;
import edu.gatech.oad.user.Patient;

/**
 * Handler that controls the saving of an appointment
 * @author Joey Slater
 * @version 1.00 
 */
public class AppointmentController {
	/**
	 * The patient who is getting the appointment
	 */
	private final Patient patient;//Used to access the appointments
	
	/**
	 * The doctor who is getting the appointment
	 */
	private Doctor doctor; //Person to set
	
	/**
	 * Constructor for the controller class
	 * @param patient the patient needing an appointment
	 */
	public AppointmentController(Patient patient){
		this.patient = patient;
	}

	/**
	 * Other constructor where doctor is definitely known 
	 * @param patient the patient needing the appointment
	 * @param doctor the doctor who will see the patient
	 */
	public AppointmentController(Patient patient, Doctor doctor){
		this.patient = patient;
		this.doctor = doctor;
	}
	
	/**
	 * Method for actually saving the appointment, 
	 * using patient's schedule Appointment method.
	 * @param appt appointment being saved
	 */
	public void save(Appointment appt){
		appt.setPatient(patient);
		appt.setDoctor(doctor); 
		patient.scheduleAppointment(appt);
		doctor.scheduleAppointment(appt);
	}
	
	/**
	 * Another save method, if Doctor is chosen later
	 * @param appt the appointment needing to be set
	 * @param newDoctor the doctor whose schedule it will be added
	 */
	public void save(Appointment appt, Doctor newDoctor){
		appt.setPatient(patient);
		appt.setDoctor(newDoctor);
		patient.scheduleAppointment(appt);
		newDoctor.scheduleAppointment(appt);
	}
	
	/**
	 * Should check to see if the user exists, or there will be an 
	 * error. Will implement tonight.
	 * @param patient the patient whose appointment needing to be deleted
	 * @param appt
	 */
	public void deleteAppointment(Appointment appt){
		//Should check to see if the user exists, or there will be an 
		//error. Will implement tonight.
		if(patient.getAppointments().contains(appt)){
			patient.getAppointments().remove(appt);
			appt.getDoctor().getAppointments().remove(appt);
		}
	}

	/**
	 * Overrides the toString method
	 * @return the name of the class
	 */
	public String toString(){
		return "AppointmentController";
	}
}